package stud.mpgame.old.game;

import org.apache.mina.core.session.IoSession;
import stud.mpgame.snapshot.ICommand;
import stud.mpgame.snapshot.ISnapshot;

import java.util.Random;

/**
 * @author f.pavel91@gmail.com
 * @version 1.0
 */
public class PlayerAddCommand implements ICommand {
    
    private int time;
    private float x;
    private float y;
    private IoSession session;

    public PlayerAddCommand(int time, IoSession session) {
        this.time = time;
        this.session = session;
        Random random = new Random();
        x = random.nextFloat() * 800;
        y = random.nextFloat() * 600;
    }

    public float getX() {
        return x;
    }

    public float getY() {
        return y;
    }

    public IoSession getSession() {
        return session;
    }

    public int getTime() {
        return time;
    }

    public int getUserID() {
        return (Integer)session.getAttribute("userID");
    }

    public void apply(ISnapshot snapshot) {
        ((GameWorld) snapshot).addUser(new Player(getX(), getY(), session));
    }

    public String toString() {
        return "PlayerAddCommand time: " + time;
        //TODO it will be more informative later
    }

}
